var is_more = !1;

Page({
    data: {
        show: !1
    },
    onLoad: function(t) {
        getApp().page.onLoad(this, t);
        if (this.data.store.is_shenhe == 0) {
          wx.setNavigationBarTitle({
            title: '购买排序'
          })
        }
        this.getData();
    },
    getData: function() {
        var e = this;
        getApp().core.showLoading({
            title: "加载中"
        }), getApp().request({
            url: getApp().api.mch.user.sort_info,
            data: {
              
            },
            success: function(t) {
                e.setData({
                    mch_info: t.data,
                    mch_setting: t.mch_setting
                }), getApp().core.hideLoading(), is_more = !1;
            }
        });
    },
    onReady: function() {
        getApp().page.onReady(this);
    },
    onShow: function() {
        getApp().page.onShow(this);
        var e = this;
        getApp().core.showLoading({
            title: "加载中"
        });
        var a = getApp().core.getStorageSync(getApp().const.USER_INFO);
        getApp().request({
            url: getApp().api.recharge.index,
            success: function(t) {
                a.money = t.data.money, getApp().core.setStorageSync(getApp().const.USER_INFO, a), 
                e.setData({
                    user_info: a,
                    list: t.data.list,
                    setting: t.data.setting,
                    date_1: t.data.date,
                    date: t.data.date.replace("-", "年") + "月"
                }), getApp().core.hideLoading();
            }
        });
    },

    click: function() {
        this.setData({
            show: !0
        });
    },
    close: function() {
        this.setData({
            show: !1
        });
    },
    GoToDetail: function(t) {
        var e = t.currentTarget.dataset.index, a = this.data.list[e];
        getApp().core.navigateTo({
            url: "/pages/balance/detail?order_type=" + a.order_type + "&id=" + a.id
        });
    },
    pay_before: function (e) {
      var t = this;
      if (typeof wx.requestSubscribeMessage === "function") {
        var tpl_msg_id = t.data.tpl_msg_id;
        return wx.requestSubscribeMessage({
          tmplIds: [tpl_msg_id],
          success: function (res) {
            console.log(res);
            t.data.form_id = tpl_msg_id
          },
          fail: function (res) {
            console.log(res);
          },
          complete: function (res) {
            t.pay();
          }
        })
      }
    },
    pay: function(e) {
      this.setData({
          show_payment: !0
      })
      
    },
    payPicker: function(t) {
          var e = t.currentTarget.dataset.index;
          this.setData({
              payment: e,
              show_payment: !1
          });
          this.pay_submit();
      },
      payClose: function() {
          this.setData({
              show_payment: !1
          });
      },
      pay_submit: function(e) {
        var t = this, n = {}, a = t.data.selected;
        if (-1 == a) {          
            return void getApp().core.showModal({
              title: "提示",
              content: "请选择充值套餐",
              showCancel: !1
           });
        } 
        
          n.pay_type = t.data.payment,
          n.pay_price = t.data.mch_setting.sort_price;
          // n.mch_id = t.data.mch_id;
        
        n.pay_price ? (getApp().core.showLoading({
            title: "提交中"
        }), getApp().request({
            url: getApp().api.mch.user.submit,
            data: n,
            method: "POST",
            success: function(e) {

              if ( 0 == e.code) {
                getApp().page.bindParent({
                  parent_id: getApp().core.getStorageSync(getApp().const.PARENT_ID),
                  condition: 1
                })
                 if (t.data.payment == 0) {
                  return setTimeout(function() {
                      getApp().core.hideLoading();
                  }, 1e3), setOnShowScene("pay"), void getApp().core.requestPayment({
                      _res: e,
                      timeStamp: e.data.timeStamp,
                      nonceStr: e.data.nonceStr,
                      package: e.data.package,
                      signType: e.data.signType,
                      paySign: e.data.paySign,
                      success: function(e) {},
                      fail: function(e) {},
                      complete: function(e) {
  
                          "requestPayment:fail" != e.errMsg && "requestPayment:fail cancel" != e.errMsg ? (getApp().page.bindParent({
                            parent_id: getApp().core.getStorageSync(getApp().const.PARENT_ID),
                            condition: 2
                        }), getApp().core.showModal({
                            title: "提示",
                            content: "充值成功",
                            showCancel: !1,
                            confirmText: "确认",
                            success: function(e) {
                                e.confirm && getApp().core.navigateBack({
                                    delta: 1
                                });
                            }
                        })) : getApp().core.showModal({
                            title: "提示",
                            content: "订单尚未支付",
                            showCancel: !1,
                            confirmText: "确认"
                        });
                      
                      }
                  });
                 } else {
                  getApp().core.showModal({
                    title: "提示",
                    content: e.msg,
                    showCancel: !1
                  })
                 }
              } else {
                getApp().core.showModal({
                  title: "提示",
                  content: e.msg,
                  showCancel: !1
                })
              }
           
                t.getData();
                getApp().core.hideLoading();
            }
        })) : getApp().core.showModal({
            title: "提示",
            content: "请选择充值金额",
            showCancel: !1
        });
    },
  
});